package com.bdk.controller;


import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdk.mapper.Role;
import com.bdk.model.RoleVO;
import com.bdk.service.IRoleService;

/**
 * 用户相关操作
 * ClassName: UserController 
 * @Description: 
 * @author ChenQuan
 * @date 2017年5月4日下午1:55:49
 */
@Controller
@RequestMapping("/role")
public class RoleController {
	
	final Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private IRoleService roleService;
	//1、角色数据列表页面
	@RequestMapping("/rList.do")
	public String rList(HttpServletRequest request, Role role, Model model) {
		return "/admin/role/rList";
	}
	//2、角色分页json数据
	@RequestMapping(value = "/getRoleJson.do",produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getUserJson(HttpServletRequest request,RoleVO roleVo, Model model) {
		 return roleService.getRoleJson(roleVo);
	}
	//3添加、修改、查看页面
	@RequestMapping("/rolepage.do")
	public String userpage(HttpServletRequest request,RoleVO r, Model model) {
		if(r.getPars().equals("add")){
			return "/admin/role/rAdd";
		}else if(r.getPars().equals("edit")){
			model.addAttribute("role", roleService.getRole(r));
			return "/admin/role/rEdit";
		}else{
			model.addAttribute("user", roleService.getRole(r));
			return "/admin/role/rInfo";
		}
	}
	/**
	 * 4、添加角色
	 * @param user
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/add.do",produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String add(HttpServletRequest request, RoleVO rolevo) {
	    return roleService.addRoleJson(rolevo,request);
	}
	
	//5、修改角色
	@RequestMapping(value="/edit.do",produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String edit(HttpServletRequest request, RoleVO rolevo) {
	     return roleService.updateRole(rolevo,request);
	}

	/**
	 * 6、删除角色
	 * 2017年11月4日下午6:40:27
	 * 说明：删除角色
	 * @param request
	 * @param model
	 * @return String List<User> json 字符串
	 */
	@RequestMapping(value = "/del.do",produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String del(HttpServletRequest request,RoleVO u, Model model) {
		 return roleService.delRoleJson(u.getRoleId());
	}
}
